package com.sq.universe.log.service.impl;

import com.sq.universe.log.entity.LogCenterEntity;
import com.sq.universe.log.service.LogCenterService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class LogCenterServiceImpl implements LogCenterService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void receiveLog(LogCenterEntity logCenterEntity) {
        /**
         * 消息异步发送
         */
        rocketMQTemplate.asyncSend("system-log", logCenterEntity, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("send successful");
            }

            @Override
            public void onException(Throwable throwable) {
                log.info("send fail; {}", throwable.getMessage());
            }
        });
    }
}
